#include "head.h"

void *threadMain(void *p)
{
    pool_t *pool = (pool_t *)p;
    while (1)
    {
        pthread_mutex_lock(&pool->lock);
        // 等待队列中有任务
        while (pool->queue.size == 0 && pool->exitFlag == 0)
        {
            pthread_cond_wait(&pool->cond, &pool->lock);
        }
        // 退出线程
        if (pool->exitFlag == 1)
        {
            pthread_mutex_unlock(&pool->lock);
            pthread_exit(NULL);
        }
        // 取出任务
        int net_fd = pool->queue.head->net_fd;
        deQueue(&pool->queue);
        pthread_mutex_unlock(&pool->lock);
        printf("要开始工作了\n");
        // 处理任务
        analyze_cmd(net_fd);
        printf("analyse end,close serve\n");

        // close(net_fd);
    }
    return NULL;
}
